home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / TransSkel++ 305 / Interface / TransSkel++.h next >
Text File  |  1996-06-28  |  16KB  |  346 lines

  1. /*
  2. ** TransSkel++.h
  3. **
  4. ** Class definitions for the TransSkel++ module.
  5. ** Include this file in your TransSkel++ source files.
  6. **
  7. **
  8. **  Fred Dushin
  9. **  email: fadushin@top.cis.syr.edu 
  10. **
  11. **  Release 3.04  May 1, 1996
  12. **  See release notes for details of changes.
  13. */
  14.  
  15.  
  16. #if !defined TRANS_SKEL_PP_H
  17. #define TRANS_SKEL_PP_H
  18.    
  19. extern "C"{
  20. #include <TransSkel.h>
  21. }
  22.  
  23.  
  24. //======================================================================/
  25. // The CApplObj Class                                                   /
  26. //                                                                      /
  27. //    Base Class: none                                                  /
  28. //    Methods:  • Error(Str255 errorStr, short code);                   /
  29. //                   Handle errors in TransSkel++                       /
  30. //                                                                      /
  31. //    Description: Every class in TransSkel++ is a subclass             /
  32. //    of the ApplObj base class.  This permits all objects              /
  33. //    to inherit the error handling facilities defined therein.         /
  34. //======================================================================/
  35.  
  36. enum SkelppErrorCode{
  37.    Skelpp_noErr,
  38.    Skelpp_fatalErr,
  39.    Skelpp_ErrBase
  40.    };
  41.    
  42. class CApplObj{
  43.    public:
  44.       // Constructors and Destructors
  45.       CApplObj( void ){}
  46.       
  47.    protected:
  48.       // Error handlers
  49.       virtual void Error( Str255 errStr, short c );
  50.    
  51.    private:
  52.       void  FatalAlert( Str255 str );
  53.       short FakeAlert( StringPtr s1, StringPtr s2, 
  54.                        StringPtr s3, StringPtr s4,
  55.                        short nButtons, short defButton, 
  56.                        short cancelButton,
  57.                        StringPtr t1, StringPtr t2, StringPtr t3 );
  58.    };
  59.  
  60.  
  61. //======================================================================/
  62. // The CApplication Class                                               /
  63. //                                                                      /
  64. //    Base Class: CApplObj Class                                        /
  65. //    Methods:  • Run(void);                                            /
  66. //                   Run the application                                /
  67. //              • doEventHook(EventRecord *evt);                        /
  68. //                   Respect the host's event hook                      /
  69. //              • doSuspendResume(Boolean inForeground);                /
  70. //                   Handle suspend/resume events                       /
  71. //              • doIdle(void);                                         /
  72. //                   Handle idle events                                 /
  73. //                                                                      /
  74. //    Description: Every program must have exactly one CApplication     /
  75. //    class (or subclass) instance, which is pointed to by the static   /
  76. //    pointer sApplication.  Typically, a programmer will define        /
  77. //    a subclass of the CApplication class for his or her purposes,     /
  78. //    making it a container for all global storage in the program.      /
  79. //                                                                      /
  80. //    The CApplication class constructor adds an event hook for         /
  81. //    inspecting events before being processed by TransSkel.  This      /
  82. //    event hook is necessary for proper handling of menu events,       /
  83. //    since TransSkel does not have anything for menus like the         /
  84. //    property list it supports for windows and dialogs.                /
  85. //======================================================================/
  86.  
  87. class CApplication : public CApplObj{
  88.    public:
  89.       // Constructors and Destructors
  90.       CApplication( SkelInitParamsPtr initParams );
  91.       virtual ~CApplication( void );
  92.       
  93.       // Event Handlers
  94.       virtual void doSuspendResume( Boolean inForeground ){}
  95.       virtual void doIdle( void ){}
  96.       virtual Boolean doEventHook( EventRecord *evt ){ return false; }
  97.       virtual void doMenuHook( void ){}
  98.       virtual void doAE( EventRecord *evt ){}
  99.  
  100.       // other methods
  101.       void Run( void ){ SkelEventLoop(); }
  102.    };
  103.  
  104.  
  105. //======================================================================/
  106. // The CMenuObj Class                                                   /
  107. //                                                                      /
  108. //    Base Class: CApplObj Class                                        /
  109. //    Methods:  • doSelect(short item);                                 /
  110. //                   Handle selection events in menu                    /
  111. //                                                                      /
  112. //    Member variables:                                                 /
  113. //       • MenuHandle menu; (protected)                                 /
  114. //         A handle to the QD menu structure                            /
  115. //                                                                      /
  116. //    Description: The CMenuObj class is a base class for all           /
  117. //    menus (apple, menubar, hierarchical, etc.).                       /
  118. //    Why is this class here?  To treat apple menus and                 /
  119. //    menubar menus consistently through the event hook.                /
  120. //                                                                      /
  121. //    Programmers should use class destructors in place of              /
  122. //    TransSkel clobber procs, so no clobber methods are                /
  123. //    defined for this class                                            /
  124. //======================================================================/
  125.  
  126. class CMenuObj : public CApplObj{
  127.    public:
  128.       // Constructors and Destructors
  129.       CMenuObj( void ){ menu = nil; }
  130.       virtual ~CMenuObj( void ){}
  131.       
  132.       // Event Handlers
  133.       virtual void doSelect( short item ){}
  134.  
  135.       //Accessors
  136.       MenuHandle GetMenuHandle( void ){ return menu; }
  137.       
  138.    protected:
  139.       MenuHandle menu;
  140.    };
  141.  
  142.  
  143. //======================================================================/
  144. // The CMenu Class                                                      /
  145. //                                                                      /
  146. //    Base Class: CMenuObj Class                                        /
  147. //    Methods:  • doSelect(short item);                                 /
  148. //                   Handle item selections in menu                     /
  149. //                                                                      /
  150. //    Member variables:                                                 /
  151. //       • MenuHandle menu; (protected)                                 /
  152. //          A handle to the QD menu structure                           /
  153. //                                                                      /
  154. //    Description: The CMenu class is used for standard (anything       /
  155. //    not an apple) menu handling.  Users of TransSkel++ will typically /
  156. //    create subclasses of the CMenu class for each menu in the         /
  157. //    application (e.g., CFileMenu, CEditMenu, etc.)  Because TransSkel /
  158. //    treates the Apple menu specially, a special CAppleMenu class      /
  159. //    is defined below.                                                 /
  160. //======================================================================/
  161.  
  162. class CMenu : public CMenuObj{
  163.    public:
  164.       // Constructors and Destructors
  165.       CMenu( void ){}
  166.       CMenu( short menuID, Boolean subMenu, Boolean drawBar );
  167.       virtual ~CMenu( void );
  168.       
  169.       // Event Handlers
  170.       virtual void doSelect( short item ){}
  171.    };
  172.  
  173.  
  174. //======================================================================/
  175. // The CAppleMenu Class                                                 /
  176. //                                                                      /
  177. //    Base Class: CMenuObj Class                                        /
  178. //    Methods:  • doSelect(short item);                                 /
  179. //                   Handle item selections in Apple menu               /
  180. //                                                                      /
  181. //    Description: The CAppleMenu class is used for managing the        /
  182. //    apple menu.  Because TransSkel treats the apple menu specially,   /
  183. //    (with SkelApple), a special class constructor is needed.  Also,   /
  184. //    TransSkel provides for no destructors for Apple menus, so         /
  185. //    the CAppleMenu class has no clobber method.                       /
  186. //======================================================================/
  187.  
  188. class CAppleMenu : public CMenuObj{
  189.    public:
  190.       // Constructors and Destructors
  191.       CAppleMenu( const StringPtr items );
  192.       virtual ~CAppleMenu( void );
  193.       
  194.       // Event Handlers
  195.       virtual void doSelect( short item ){}
  196.    };
  197.  
  198.    
  199. //======================================================================/
  200. // The CWindow Class                                                    /
  201. //                                                                      /
  202. //    Base Class: CApplObj Class                                        /
  203. //    Methods:  • doMouseClick(Point where, long when, short modifiers);/
  204. //                   Handle mouse clicks in window                      /
  205. //              • doKeyClick(short c, short code, short modifiers);     /
  206. //                   Handle key clicks in window                        /
  207. //              • doUpdate(Boolean resized);                            /
  208. //                   Handle Update events in window                     /
  209. //              • doActivate(Boolean active);                           /
  210. //                   Handle Activate events in window                   /
  211. //              • doClose(void);                                        /
  212. //                   Handle closing window (default method              /
  213. //                   hides window via HideWindow())                     /
  214. //              • doIdle(void);                                         /
  215. //                   Handle idle events in window                       /
  216. //              • doShow(void);                                         /
  217. //                   Display window (Calls Show/SelectWindow())         /
  218. //              • GetWindowPtr(void);                                   /
  219. //                   Returns WindowPtr to QD window struct              /
  220. //                                                                      /
  221. //    Member variables:                                                 /
  222. //       • WindowPtr wind; (protected)                                  /
  223. //          A pointer to the QD window structure                        /
  224. //                                                                      /
  225. //    Description: The CWindow class is the base class for all window   /
  226. //    objects in TransSkel++.  Users will typically create subclasses   /
  227. //    of the CWindow class (e.g., CDrawWindow, CStatusWindow, etc.)     /
  228. //    and override any of the above methods and/or create new ones.     /
  229. //======================================================================/
  230.  
  231. class CWindow : public CApplObj{
  232.    public:
  233.       // Constructors and Destructors
  234.       CWindow( void ){}
  235.       CWindow( Ptr wStorage,
  236.                Rect *boundsRect,
  237.                Str255 title,
  238.                Boolean visible,
  239.                int procID,
  240.                WindowPtr behind,
  241.                Boolean goAway,
  242.                long refCon,
  243.                Boolean frontIdle );
  244.       CWindow( short windID, 
  245.                Ptr wStorage, 
  246.                WindowPtr behind, 
  247.                Boolean frontIdle );
  248.       virtual ~CWindow( void );
  249.       
  250.       // Event Handlers
  251.       virtual void doMouseClick( Point where, long when, 
  252.                                  short modifiers ){}
  253.       virtual void doKeyClick( short c, short code, 
  254.                                short modifiers){}
  255.       virtual void doUpdate( Boolean resized ){}
  256.       virtual void doActivate( Boolean active ){}
  257.       virtual void doClose( void ){ HideWindow( wind ); }
  258.       virtual void doIdle( void ){}
  259.       virtual void doShow( void );
  260.       
  261.       // Accessors
  262.       WindowPtr GetWindowPtr( void ){ return wind; }
  263.    
  264.    protected:
  265.       void SavePort( void ){    GetPort( &oldPort );
  266.                                 SetPort( wind ); }
  267.       void RestorePort( void ){ SetPort( oldPort ); }
  268.       WindowPtr wind;
  269.  
  270.    private:
  271.       WindowPtr oldPort;
  272.     };
  273.  
  274.    
  275. //======================================================================/
  276. // The CDialog Class                                                    /
  277. //                                                                      /
  278. //    Base Class: CApplObj Class                                        /
  279. //    Methods:  • doFilter(EventRecord *evt, short *item);              /
  280. //                   dialog filter proc                                 /
  281. //              • doSelect(short item);                                 /
  282. //                   Handle item selections in dialog                   /
  283. //              • doClose(void);                                        /
  284. //                   Handle closing dialog (default method              /
  285. //                   hides window via HideWindow())                     /
  286. //              • doShow(void);                                         /
  287. //                   Display dialog (Calls Show/SelectWindow())         /
  288. //              • GetDialogPtr(void);                                   /
  289. //                   Returns DialogPtr to QD dialog struct              /
  290. //                                                                      /
  291. //    Member variables:                                                 /
  292. //       • DialogPtr dlog; (protected)                                  /
  293. //          A pointer to the QD dialog structure                        /
  294. //                                                                      /
  295. //    Description: The CDialog class is the base class for all dialog   /
  296. //    objects in TransSkel++.  Users will typically create subclasses   /
  297. //    of the CDialog class (e.g., CAboutDialog, CSettingDialog, etc.)   /
  298. //    and override any of the above methods and/or create new ones.     /
  299. //======================================================================/
  300.    
  301.  
  302. class CDialog : public CApplObj{
  303.    public:
  304.       // Constructors and Destructors
  305.       CDialog( void ){}
  306.       CDialog( Ptr dStorage,
  307.                Rect *boundsRect,
  308.                Str255 title,
  309.                Boolean visible,
  310.                int procID,
  311.                DialogPtr behind,
  312.                Boolean goAway,
  313.                long refCon,
  314.                Handle items);
  315.       CDialog( short dlogID, Ptr wStorage, WindowPtr behind );
  316.       virtual ~CDialog( void );
  317.       
  318.       // Event Handlers
  319.       virtual Boolean doFilter( EventRecord *evt, short *item )
  320.                       { return false; }
  321.       virtual void doSelect( short item ){}
  322.       virtual void doClose( void )
  323.                    { HideWindow( dlog ); }
  324.       virtual void doShow( void );
  325.       
  326.       // Accessors
  327.       DialogPtr GetDialogPtr( void )
  328.                 { return dlog; }
  329.    
  330.    protected:
  331.       void SavePort( void ){    GetPort( &oldPort );
  332.                                 SetPort( dlog ); }
  333.       void RestorePort( void ){ SetPort( oldPort ); }
  334.       DialogPtr dlog;
  335.  
  336.    private:
  337.       DialogPtr oldPort;
  338.    };
  339.  
  340.  
  341. //-- FUNCTION PROTOTYPES -----------------------------------------------/
  342.  
  343. CWindow * GetCWindow(WindowPtr wind);
  344. CDialog * GetCDialog(DialogPtr dlog);
  345.  
  346. #endif